<?php

/**
 * comisiones actions.
 *
 * @package    cronos-doctrine
 * @subpackage comisiones
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class comisionesActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->saldos = Doctrine_Core::getTable('SaldoTemporal')
      ->createQuery('a')
      ->execute();
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new SaldoTemporalForm();
    $this->form->setWidget('concepto_cf_id', new sfWidgetFormInputHidden(array(),array('value' => 2)));
    $this->form->setWidget('tipo', new sfWidgetFormInputHidden(array(),array('value' => 1)));
    $this->form->setWidget('fecha', new sfWidgetFormInput(array(), array('value' => date('Y-m-d'),'size' => 15, 'id' => 'fechaDashboard', 'readonly'=>'readonly')));
    $this->form->setWidget('concepto', new sfWidgetFormTextarea(array('default' => 'Monto recibido adicional por cliente nuevo')));
    
    $this->operador_id = $request->getParameter('operador_id');
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new SaldoTemporalForm();
    $this->processForm($request, $this->form);
    $this->setTemplate('new');
    
    
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($comisiones = Doctrine_Core::getTable('SaldoTemporal')->find(array($this->getUser()->getAttribute('agente_user_comisiones_id'))), sprintf('Object comisiones does not exist (%s).', $this->getUser()->getAttribute('agente_user_comisiones_id')));
    $this->form = new SaldoTemporalForm($comisiones);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($comisiones = Doctrine_Core::getTable('SaldoTemporal')->find(array($request->getParameter('id'))), sprintf('Object comisiones does not exist (%s).', $request->getParameter('id')));
    $this->form = new SaldoTemporalForm($comisiones);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($comisiones = Doctrine_Core::getTable('SaldoTemporal')->find(array($request->getParameter('id'))), sprintf('Object comisiones does not exist (%s).', $request->getParameter('id')));
    $comisiones->delete();

    $this->redirect('comisiones/index');
  }
 

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $comisiones = $form->save();

      $this->redirect('comisiones/index?fecha='.$comisiones->getFecha().'&operador_id='.$comisiones->getOperadorId());
      
    }
  }
}
